﻿
namespace VXCompany.SilverlightLogging.MVVM.Models.Stores
{

	public class SiteStore : ApplicationStore
	{
		public SiteStore()
		{
#if WINDOWS_PHONE
			throw new System.Exception("Site Store not available on windows phone.");
#endif
			Initialize();
		}

		/// <summary>
		/// Initializes Store.
		/// </summary>
		protected override void InitializeImpl()
		{
#if WINDOWS_PHONE
			throw new System.Exception("Site Store not available on windows phone.");
#else
			try
			{
				this.PlatformStore = System.IO.IsolatedStorage.IsolatedStorageSettings.SiteSettings;
				IsStorageAvailable = true;
			}
			catch (System.IO.IsolatedStorage.IsolatedStorageException)
			{
				IsStorageAvailable = false;
			}			
#endif
		}

		/// <summary>
		/// Saves changes.
		/// </summary>
		protected override void SaveImpl()
		{
#if WINDOWS_PHONE
			throw new System.Exception("Site Store not available on windows phone.");
#else
			if (!PlatformStore.ContainsKey(APPSETTINGS_KEY))
			{
				PlatformStore.Add(APPSETTINGS_KEY, InnerList);
			}
			else
			{
				PlatformStore[APPSETTINGS_KEY] = InnerList;
			}

			System.IO.IsolatedStorage.IsolatedStorageSettings.SiteSettings.Save();
#endif
		}
	}

}
